import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author Dennis Li
 * @date 2020/7/27 16:08
 */
public class GenericDemo {

    static class Fruit {
    }

    static class Apple extends Fruit {
    }

    static class GoodApple extends Apple {
    }

    public static void main(String[] args) {
        // 不能添加任何元素，只能提取
        ArrayList<? extends Fruit> apples = new ArrayList<>(Arrays.asList(new Apple(), new Apple()));
        System.out.println(apples.get(0));
        // 可以添加Apple及其子类
        ArrayList<? super Apple> fruits = new ArrayList<>();
        fruits.add(new Apple());
        fruits.add(new GoodApple());
    }


}
